import { useFetch } from '../../Scripts/hooks/useFetch.js'

export function useFetchSuggestion() {

  const fetchSuggestion = async configObj => {
    const triggerLength = configObj.triggerLength || 4;

    if (configObj.value && configObj.value.length >= triggerLength) {
      const { data, status: { code, msg } } = await useFetch({
        url: `${configObj.url}?actions=${configObj.method}`,
        data: {
          type: `${configObj.method}`,
          [configObj.name]: configObj.value
        }
      });
      const result = data.value.filter(item => item.rownum < 100);
      configObj.callback(result);
    }
  }

  return { fetchSuggestion }
}